Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpf_iter and cgroup support #110

Merged
merged 2 commits into from
Jun 17, 2020
Merged

bpf_iter and cgroup support #110

merged 2 commits into from
Jun 17, 2020

Conversation

lmb
Copy link
Collaborator

@lmb lmb commented Jun 16, 2020

Use the low-level APIs to construct high-level Links for attaching to cgroups and bpf_iter. Especially the cgroup support is interesting, because it falls back to BPF_PROG_ATTACH after trying bpf_link on older kernel.

New API:

 var ErrNotSupported = internal.ErrNotSupported
 func RawAttachProgram(opts RawAttachProgramOptions) error
 func RawDetachProgram(opts RawDetachProgramOptions) error
+type CgroupOptions struct{ ... }
+type Iter struct{ ... }
+    func AttachIter(opts IterOptions) (*Iter, error)
+    func LoadPinnedIter(fileName string) (*Iter, error)
+type IterOptions struct{ ... }
 type Link interface{ ... }
+    func AttachCgroup(opts CgroupOptions) (Link, error)
+    func LoadPinnedCgroup(fileName string) (Link, error)
 type RawAttachProgramOptions struct{ ... }
 type RawDetachProgramOptions struct{ ... }
 type RawLink struct{ ... }

lmb added 2 commits June 16, 2020 15:16
Use the BPF_PROG_ATTACH and bpf_link infrastructure to implement a
generic way to attach to cgroups. Older kernels will use BPF_PROG_ATTACH,
newer ones bpf_link.
bpf_iter allows writing dumpers for various kernel data structures like BPF maps.
@lmb
Copy link
Collaborator Author

lmb commented Jun 16, 2020

I'm not sure about the LoadPinned* methods. I think it might be possible to write a LoadPinnedLink function which uses BPF_GET_OBJ_INFO (or whatever that is called) to determine what kind of Link we are dealing with, which would make these obsolete.

Copy link
Contributor

@florianl florianl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me! and great work!

Do you think raw_tracepoints should also be in link?

@lmb
Copy link
Collaborator Author

lmb commented Jun 17, 2020

Yes, if we can make them conform to Link and if we don't need new dependencies.

Copy link
Member

@tklauser tklauser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants